<?php
include_once("../configure/admin.config.inc.php");	//--> admin global var
include_once("db.inc.php");							//--> db global var
include_once("Smarty.class.php");					//--> out template
include_once("Operation.php");						//--> Operation
include_once("Attributes.php");						//--> Attributes
require_once("controlHeader.php");					//--> system control header
	

$objOperate		= new Operation($objSession->getLanguage());	//--> Operation
$objAttributes 	= new Attributes(DB_TAG_SYSTEM, $uid);			//--> Attributes

$error_message = '';
if(isset($_GET['page']))
	$page = $_GET['page'];
else 
	$page = 1;
	
$arrOperate = $objOperate->arrGetFromGroupIDAndMenuID($gid, $menuid);
if(count($arrOperate) > 0){
	$strQuery = $_SERVER["REQUEST_URI"];
	$arrUrlInfo 	= pathinfo($strQuery);
	$selfFileName	= $arrUrlInfo['filename'];
	
	$arrOperateAllInfo = $objOperate->listFromCustom($arrOperate, " WHERE id in (".implode(",", $arrOperate).") AND name != 'Add'");
	
	$i = 0; 
	foreach($arrOperateAllInfo as $key => $value){
		$strFileName = $selfFileName."_".$value['name'].".php";

		if(file_exists($strFileName)){
			$arrOperateInfo[$i]['name'] 		= $value['name'];
			$arrOperateInfo[$i]['viewName'] 	= $value['name'];
			
			$i++;
		}
	}
}

$arrDataList = array();
$arrTmpStack = array();
$arrLevelStack = array();
$i = 0;
$k = 0;
$iDisCount = DISPLAY_DATA_SIZE;
array_push($arrTmpStack,'0');

while(sizeof($arrTmpStack) > 0){
	$strtmp = array_pop($arrTmpStack);
	$i 		= array_pop($arrLevelStack);
	if($strtmp > 0){
		$arrback = $objAttributes->getFromID($arrOperate, $LANGEUAGE_ID, $strtmp);
		if(is_array($arrback)){
			$tmp = '';
			for($j = 1; $j < $i; $j++){
				$tmp.='&nbsp;&nbsp;&nbsp;&nbsp;';
			}
			$status = '';
			$iStart = ($page - 1) * $iDisCount;
			$iEnd	= $iStart + $iDisCount;
			
			if($k >= $iStart && $k < $iEnd)
				$arrDataList[] = array("id" => $arrback['id'], "sorts" => $arrback['sorts'], "isLeaf" => $arrback['isLeaf'], "name" => $tmp.$arrback['name'], "level" => $i);
			
			$k++;
			if($k >= $iEnd)
				break;
		}
	}

	$mixBack = $objAttributes->listFromCustom($arrOperate, " WHERE parentid='$strtmp' ORDER BY sorts DESC");
	if(is_array($mixBack)){
		$i++;
		foreach($mixBack as $value){
			array_push($arrTmpStack,$value['id']);
			array_push($arrLevelStack,$i);
		}
	}
}

$objAttributes->mutilPager($objAttributes->getCount(), $page, $iDisCount, '');

/*----- out html -----*/
$smarty = new Smarty();		//----- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = COMPILE_SYS_DIR;

$smarty->assign('error_message', $error_message);
$smarty->assign('backurl',$backurl);

$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);

$smarty->assign('selfFileName', $selfFileName);
$smarty->assign('arrOperateInfo', $arrOperateInfo);

$smarty->assign('arrDataList', $arrDataList);
$smarty->assign('PAGE_BAR', $objAttributes->pagenav);

$smarty->display('listAttributes.htm');
?>
